/*********************************************************
 Main Window! 
 
 Click the "Run" button to Run the simulation.
 
 Change the geometry, flow conditions, numercial parameters
 visualizations and measurments from this window. 
 
 *********************************************************/
//BDIM flow;
//CircleBody body;
//FloodPlot flood;
//
//void setup(){
//  int n=(int)pow(2,6)+2; // number of grid points
//  size(400,400);         // display window size
//  Window view = new Window(n,n);
//
//  body = new CircleBody(n/3,n/2,n/8,view); // define geom
//  flow = new BDIM(n,n,1.5,body);           // solve for flow using BDIM
////  flow = new BDIM(n,n,0,body,0.01,true);   // QUICK with adaptive dt
//  flood = new FloodPlot(view);
//  flood.range = new Scale(-.75,.75);
//  flood.setLegend("vorticity");
//}
//void draw(){
//  body.update();
//  flow.update(body);
//  flow.update2();
//  flood.display(flow.u.vorticity());
//  body.display();
//}
//void mousePressed(){body.mousePressed();}
//void mouseReleased(){body.mouseReleased();}



import processing.video.*;
MovieMaker mm;
InlineFoilTest test;
SaveData dat;
float maxT;
float numframes = 250;
float frame = 0;

void setup() {
  int Re = 6000, nflaps = 2;;
  float stru = .45, stk = -135*PI/180, hc = 1, dAoA = 25*PI/180, uAoA = 0*PI/180;
  int resolution = 32, xLengths=7, yLengths=7, xStart = 3, zoom = 3;
  //int resolution = 64, xLengths=7, yLengths=6, xStart = 3, zoom = 1;
  maxT = (int)(2*hc/stru*resolution*nflaps);

  test = new InlineFoilTest(resolution, xLengths, yLengths, xStart, zoom, Re, true);
  test.setFlapParams(stru, stk, dAoA, uAoA, hc, "ClosedLoop");

  String datapath = "C:\\Users\\jsi\\Documents\\Research\\CFD\\Data\\";
  mm = new MovieMaker(this, width, height, datapath+"flap.mov", 30);
  dat = new SaveData(datapath+"pressure.txt", test.foil.coords, resolution, xLengths, yLengths, zoom);

  dat.saveParam("stru", stru);
  dat.saveParam("stk", stk);
  dat.saveParam("hc", hc);
  dat.saveParam("dAoA", dAoA);
}
void draw() {
  test.update();
  test.display();
  dat.addData(test.t, test.foil.pressForce(test.flow.p), test.foil, test.flow.p);

  if (frame<test.t*numframes/maxT) {
    frame = frame+1;
    mm.addFrame();
  }

  if (test.t>=maxT) {
    dat.finish();
    mm.finish();
    exit();
  }
}
void keyPressed() {
  mm.finish();
  dat.finish();
  exit();
}

